package com.lianniu.mgr.cms.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.cms.model.ChannelProductRecomendVo;
import com.lianniu.mgr.cms.service.IChannelProductRecomendService;
import com.lianniu.mgr.pagination.PaginationInfo;

@Controller
@RequestMapping("/rest/ChannelPR")
public class ChannelProductRecomendRestController {

private final static Logger logger = Logger.getLogger(ChannelProductRecomendRestController.class);
	
	@Autowired
	private IChannelProductRecomendService channelProductRecommendService;
	
	@RequestMapping(value="/ChannelPRList",method={RequestMethod.GET,RequestMethod.POST})
	public @ResponseBody BaseResult ChannelPRList(HttpServletRequest request, ChannelProductRecomendVo curVo, PaginationInfo paginationInfo)
	 {
	       logger.info("ChannelRestController  ChannelPRList begin.");
	       try {
	           
	           logger.info("ChannelPRList begin.");          
	           BaseResult baseResult = channelProductRecommendService.selectByChannelProductRecomendForPage(curVo, paginationInfo);
	           logger.info("ChannelPRList end.");
	           logger.info("ChannelRestController ChannelPRList end.");
	           return baseResult;
	       } catch (Exception e) {
	       logger.error("ChannelRestController ChannelPRList error:" + e.getMessage());
	       logger.error("ChannelRestController ChannelPRList end.");
	       return BaseResult.exception(e.getMessage());
	     }
	  }
	
	@RequestMapping(value = {"/ChannelPRAdd"}, method = RequestMethod.POST)
	public @ResponseBody BaseResult ChannelPRAdd(HttpServletRequest request,ChannelProductRecomendVo curVo) {
	      logger.info("ChannelRestController ChannelPRAdd begin.");      
	      logger.info("ChannelRestController ChannelPRAdd:"+ JSON.toJSONString(curVo));
	      try {
	          logger.info("ChannelPRAdd begin.");
	        
	          BaseResult baseResult = channelProductRecommendService.insertChannelProductRecomend(curVo);
	          logger.info("ChannelPRAdd baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("ChannelPRAdd end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("ChannelPRAdd error:"+e.getMessage());
	      logger.info("ChannelRestController ChannelPRAdd end.");
	      return BaseResult.exception(e.getMessage());
	    }

	  }
	
	 
	@RequestMapping(value = {"/ChannelPREdit"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult ChannelPREdit(HttpServletRequest request,ChannelProductRecomendVo curVo) {
	      logger.info("ChannelRestController ChannelPREdit begin.");      
	      logger.info("ChannelRestController ChannelPREdit:"+ JSON.toJSONString(curVo));
	      try {
	          logger.info("ChannelPREdit begin.");
	          BaseResult baseResult = channelProductRecommendService.updateById(curVo);
	          logger.info("ChannelPREdit baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("ChannelPREdit end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("ChannelRestController error:"+e.getMessage());
	      logger.info("ChannelRestController ChannelPREdit end.");
	      return BaseResult.exception(e.getMessage());
	    }
	  }
	  
	
	 @RequestMapping(value="/selectChannelPRById",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult selectChannelPRById(HttpServletRequest request,ChannelProductRecomendVo curVo) {
	        logger.info("ChannelRestController selectChannelPRById begin.");
	        try {
	                    
	          BaseResult baseResult = channelProductRecommendService.selectById(curVo);
	          logger.info("ChannelRestController end.");
	          logger.info("ChannelRestController selectChannelPRById end.");
	          return baseResult;
	        } catch (Exception e) {
	          logger.error("ChannelRestController selectChannelPRById error:" + e.getMessage());
	          logger.error("ChannelRestController selectChannelPRById end.");
	          return BaseResult.exception(e.getMessage());
	        }
	  } 
	 
	 @RequestMapping(value = {"/ChannelPRDel"}, method = RequestMethod.POST)
	  public @ResponseBody BaseResult ChannelPRDel(HttpServletRequest request) {
	      logger.info("ChannelRestController ChannelPRDel begin.");
	     try {          
	          logger.info("ChannelPRDel begin.");
	          BaseResult baseResult = channelProductRecommendService.deleteChannelProductRecomendBatch(request.getParameter("ids").split(","));		
	          logger.info("ChannelPRDel baseResult:" + JSON.toJSONString(baseResult));
	          logger.info("ChannelPRDel end.");
	          
	          logger.info("ChannelRestController ChannelPRDel end.");
	          return baseResult;

	    } catch (Exception e) {
	      logger.error("ChannelRestController ChannelPRDel error:" + e.getMessage());
	      logger.info("ChannelRestController ChannelPRDel end.");
	      return BaseResult.exception(e.getMessage());
	    }

	  }
	 
	
}
